package com.cw.maintenance.action;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Icon;
import javax.swing.JOptionPane;

import com.cw.maintenance.MaintenancePanel;

public class DeleteAction extends AbstractAction {
	MaintenancePanel target;

	public DeleteAction() {
		super();
	}

	public DeleteAction(String name) {
		super(name);
	}

	public DeleteAction(String name, Icon icon, MaintenancePanel tar) {
		super(name, icon);
		this.target = tar;
	}

	/**
	 * Invoked when an action occurs.
	 * 
	 * @param e
	 *            ActionEvent
	 * @todo Implement this java.awt.event.ActionListener method
	 */
	public void actionPerformed(ActionEvent e) {
//		int[] row = target.dataTable.getSelectedRows();
		int[] row = null;
		int[] sel = new int[row.length];
		for (int i = 0; i < row.length; i++) {
			sel[i] = row[row.length - 1 - i];
		}

		if (row.length > 0) {
			int confirm = JOptionPane.showInternalConfirmDialog(target,
					"Are you sure delete these " + row.length + " records?",
					"Confirm", JOptionPane.YES_NO_OPTION);
			if (confirm == JOptionPane.YES_OPTION) {
				for (int i = 0; i < sel.length; i++) {
					Object qh = target.getTable().getValueAt(sel[i], 0);
					if (qh != null || qh.equals("")) {// delete null record
						target.deleteRec((String) qh, sel[i]);
					}

				}
			}
		}
	}
}
